# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=smpeg
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.5
pkgrel=2
pkgdesc="SDL MPEG Player Library (mingw-w64)"
arch=('any')
url="https://icculus.org/smpeg/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gtk2"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "subversion")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-SDL")
options=('staticlibs' 'strip')
source=("${_realname}::svn://svn.icculus.org/smpeg/tags/release_${pkgver//./_}"
        no-undefined.patch)
sha256sums=('SKIP'
            'd9c89f26abb9c5c6341876a613dac805e3c4ded590c99668104fcc453a4f412d')

prepare() {
  cd "${srcdir}"/${_realname}
  patch -p1 -i ${srcdir}/no-undefined.patch
  ./autogen.sh
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}/"

  CFLAGS+=" -Wno-error=narrowing"
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --mandir=${MINGW_PREFIX}/share/man \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  # hacky way of resolving conflicts
  rm ${pkgdir}${MINGW_PREFIX}/bin/plaympeg
  rm -r ${pkgdir}${MINGW_PREFIX}/share/man
}
